﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

using Castle.ActiveRecord;
using NHibernate.Criterion;
using LIB;
using System.Collections;

public partial class admin_newsletter_template : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
       using (new SessionScope())
        {
            string page = ConvertUtility.ToString(Request.QueryString["page"]);
            int pageIndex = 0;
            if (pageIndex == 0)
                pageIndex = 1;

            bindTemplate(pageIndex);
        }
      
    }
    protected void bindTemplate(int pageIndex)
    {
        try
        {
            Newsletter_Info[] lstNewsLetter = Newsletter_Info.FindAll(Order.Desc("id"));
            repTemplate.DataSource = lstNewsLetter.Skip((pageIndex - 1) * 10).Take(10);
            repTemplate.DataBind();
            int totalPage = (int)Math.Ceiling(ConvertUtility.ToDouble(lstNewsLetter.Length) / 10);
            pagerbot.Text = ConvertUtility.buidPaging3(totalPage, pageIndex, HttpContext.Current.Request.Url.LocalPath);
        }
        catch (Exception ex) { }

    }


    protected void btnDel_Click(object sender, EventArgs e)
    {
        try
        {
            string[] arrKeyDel = hidKeyDel.Value.Split('|');

            for (int i = 0; i < arrKeyDel.Length - 1; i++)
            {
                Newsletter_Info memInfo = Newsletter_Info.Find(Convert.ToInt32(arrKeyDel[i].Trim()));
                memInfo.DeleteAndFlush();
            }
            Response.Redirect("/admin/newsletter/template.aspx");

        }
        catch (Exception ex)
        {
            lblMessage.Text = "Không thể xóa.Hãy thử lại";
        }
    }
    
}